package com.toocms.jinjuhang.ui.mine.order.evaluate

import android.os.Bundle
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.RelativeSizeSpan
import androidx.databinding.ObservableField
import com.blankj.utilcode.util.StringUtils
import com.toocms.jinjuhang.R
import com.toocms.jinjuhang.config.Constants
import com.toocms.jinjuhang.data.goods.CommodityItemData
import com.toocms.jinjuhang.ui.commodity.detils.CommodityDetailsFgt
import com.toocms.tab.base.BaseViewModel
import com.toocms.tab.base.ItemViewModel
import com.toocms.tab.binding.command.BindingAction
import com.toocms.tab.binding.command.BindingCommand

class OrderEvaluateResultRecommendItemModel(
    viewModel: BaseViewModel<*>, val item: ObservableField<CommodityItemData>
) : ItemViewModel<BaseViewModel<*>>(viewModel) {

    val itemClickBindingCommand = BindingCommand<BindingAction>(BindingAction {
        item.get()?.apply {
            val bundle = Bundle()
            bundle.putString(Constants.BundleKey.KEY_GOODS_ID, goods_id)
            viewModel.startFragment(CommodityDetailsFgt::class.java, bundle)
        }
    })


    fun price(commodityType: String?, sum: String?) = when (commodityType) {
        Constants.Extra.COMMODITY_TYPE_INTEGRAL -> {
            val sum = if (sum.isNullOrEmpty()) "00" else sum
            SpannableStringBuilder("$sum${StringUtils.getString(R.string.str_integral)}").apply {
                setSpan(
                    RelativeSizeSpan(0.8f), sum.length, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                )
            }
        }
        else -> {
            val sum = if (sum.isNullOrEmpty()) "0.00" else sum
            "${StringUtils.getString(R.string.str_money_symbol)}$sum"
        }
    }

}